import { _decorator, Component, EventTouch, instantiate, Node, Prefab } from 'cc';
import { ModuleBase } from './ModuleBase';
import { gameConfig } from './Configs';
import { resMgr } from './Res/ResMgr';
import { PrefabMgr } from './Res/SpecialResMgr';
import { Player } from './Player';
const { ccclass, property } = _decorator;

@ccclass('PlayerLayers')
export class PlayerLayers extends ModuleBase {

    private _playerTs: Player = null;
    private _isClick: boolean = false;
    onInit(...rest: any[]): void {
        this._createPlayer();
    }

    private _createPlayer() {
        let index = gameConfig.roleIndex;
        let rolePre = resMgr.getMgr<PrefabMgr>("PrefabMgr").getRes<Prefab>("Role" + index);
        let roleNode = instantiate(rolePre);
        roleNode.name = "Player"
        roleNode.parent = this.node;
        let playerTs: Player = roleNode.getComponent(Player);
        this._playerTs = playerTs;
        this._playerTs.init(index);
    }

    changeClickState(isClick: boolean) {
        this._isClick = isClick;
        this._playerTs.isStartRotation(this._isClick);
    }

    onTouchStart(event: EventTouch) {
        this._playerTs.onTouchStart(event);
    }
    onTouchEnd(event: EventTouch) {
        this._playerTs.onTouchEnd(event);
    }

    playerRun() {
        this._playerTs.run();
    }
}


